package com.wan.uitls

import com.google.gson.JsonObject
import com.wan.base.BaseBean
import com.wan.base.WanApp
import com.wan.entity.*
import retrofit2.Call

class ApiManager(var clazz: Any) : APIServices{

    private var helper = RetrofitHelper.get()
    private var apiServices: APIServices? = helper.getApiServices()


    override fun getArticleList(page: Int): Call<BaseBean<HomeArtEntity>> {

        var call = apiServices!!.getArticleList(page)
        helper.addCall(clazz, call)
        return call
    }

    override fun getHomeBannerList(): Call<BaseBean<ArrayList<HomeBannerEntity>>> {
        var call = apiServices!!.getHomeBannerList()
        helper.addCall(clazz, call)
        return call
    }

    override fun getProjectList(): Call<BaseBean<ArrayList<ProjectBean>>> {
        var call = apiServices!!.getProjectList()
        helper.addCall(clazz, call)
        return call
    }

    override fun getProjectItemList(page: Int, cid: Int): Call<BaseBean<HomeArtEntity>> {
        var call = apiServices!!.getProjectItemList(page,cid)
        helper.addCall(clazz, call)
        return call
    }

    override fun getSystemTreeItemList(): Call<BaseBean<ArrayList<SystemTabEntity>>> {
        var call = apiServices!!.getSystemTreeItemList()
        helper.addCall(clazz, call)
        return call
    }

    override fun getSystemArtItemList(page: Int, cid: Int): Call<BaseBean<HomeArtEntity>> {
        var call = apiServices!!.getSystemArtItemList(page,cid)
        helper.addCall(clazz, call)
        return call
    }

    override fun getNavigationItemList(): Call<BaseBean<ArrayList<NavigationArtEntity>>> {
        var call = apiServices!!.getNavigationItemList()
        helper.addCall(clazz, call)
        return call
    }

    override fun getCollectionList(page: Int,cookie:String): Call<BaseBean<HomeArtEntity>> {
        var logginMessage = CommonUtils.getLogginMessage(WanApp.sContext)
        var call = apiServices!!.getCollectionList(page,logginMessage!!.token)
        helper.addCall(clazz, call)
        return call
    }

    override fun postCollectionArticle(id: Int,cookie: String): Call<JsonObject> {
        var logginMessage = CommonUtils.getLogginMessage(WanApp.sContext)
        var call = apiServices!!.postCollectionArticle(id,logginMessage!!.token)
        helper.addCall(clazz, call)
        return call
    }

    override fun postUnCollectionArticle(id: Int,cookie: String): Call<JsonObject> {
        var logginMessage = CommonUtils.getLogginMessage(WanApp.sContext)
        var call = apiServices!!.postUnCollectionArticle(id,logginMessage!!.token)
        helper.addCall(clazz, call)
        return call
    }

    override fun postSearchArticle(page: Int, k: String): Call<BaseBean<HomeArtEntity>> {
        var call = apiServices!!.postSearchArticle(page,k)
        helper.addCall(clazz, call)
        return call
    }

    override fun getHotKeys(): Call<BaseBean<ArrayList<CommonlyEntity>>> {
        var call = apiServices!!.getHotKeys()
        helper.addCall(clazz, call)
        return call
    }

    override fun getCommonlyWebSite(): Call<BaseBean<ArrayList<CommonlyEntity>>> {
        var call = apiServices!!.getCommonlyWebSite()
        helper.addCall(clazz, call)
        return call
    }

    override fun postLoginData(userName: String, password: String): Call<BaseBean<LoginEntity>> {
        var call = apiServices!!.postLoginData(userName,password)
        helper.addCall(clazz, call)
        return call
    }

    override fun postRegisterData(userName: String, password: String, repassword: String): Call<BaseBean<LoginEntity>> {
        var call = apiServices!!.postRegisterData(userName,password,repassword)
        helper.addCall(clazz, call)
        return call
    }

    override fun getLogoutData(): Call<JsonObject> {
        var call = apiServices!!.getLogoutData()
        helper.addCall(clazz, call)
        return call
    }
}